package com.hui.platform.falseworkapi.service.business.user.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hui.platform.falseworkapi.common.core.vo.PageData;

import com.hui.platform.falseworkapi.service.business.user.bo.TbAuthoritiesBO;
import com.hui.platform.falseworkapi.service.business.user.dto.TbAuthoritiesDTO;
import com.hui.platform.falseworkapi.service.business.user.convert.TbAuthoritiesConvert;

import com.hui.platform.falseworkapi.service.business.user.entity.TbAuthorities;
import com.hui.platform.falseworkapi.service.business.user.mapper.TbAuthoritiesMapper;
import com.hui.platform.falseworkapi.service.business.user.service.TbAuthoritiesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 权限表 服务实现类
 *
 * @author hui
 * @since 2020-04-17
 */
@Service
public class TbAuthoritiesServiceImpl extends ServiceImpl<TbAuthoritiesMapper, TbAuthorities> implements TbAuthoritiesService {

    @Override
    public TbAuthoritiesBO readById(Long id) {
        return TbAuthoritiesConvert.INSTANCE.do2bo(getById(id));
    }

    @Override
    public List<TbAuthoritiesBO> readByIds(List<Long> ids) {
        return TbAuthoritiesConvert.INSTANCE.do2bo(new ArrayList<>(listByIds(ids)));
    }

    @Override
    public List<TbAuthoritiesBO> readList(TbAuthoritiesDTO condition) {
        return TbAuthoritiesConvert.INSTANCE.do2bo(list(Wrappers.lambdaQuery(TbAuthoritiesConvert.INSTANCE.dto2do(condition))));
    }

    @Override
    public PageData<TbAuthoritiesBO> readPage(Long pageNum, Long pageSize, TbAuthoritiesDTO condition) {
        IPage<TbAuthorities> page = page(new Page<>(pageNum, pageSize), Wrappers.lambdaQuery(TbAuthoritiesConvert.INSTANCE.dto2do(condition)));
        return PageData.build(page, TbAuthoritiesConvert.INSTANCE.do2bo(page.getRecords()));
    }

    @Override
    public Long createOne(TbAuthoritiesDTO dto) {
        TbAuthorities domain = TbAuthoritiesConvert.INSTANCE.dto2do(dto);
        return save(domain) ? domain.getId() : null;
    }

    @Override
    public Long updateOne(Long id, TbAuthoritiesDTO dto) {
        return updateById(TbAuthoritiesConvert.INSTANCE.dto2do(dto).setId(id)) ? id : null;
    }

    @Override
    public Long deleteById(Long id) {
        return removeById(id) ? id : null;
    }

    @Override
    public List<Long> deleteByIds(List<Long> ids) {
        return removeByIds(ids) ? ids : null;
    }

}
